//
///*
// * VenusGPS.cpp
// *
// *  Created on: Nov 28, 2011
// *      Author: mat
// */
//
//#include "GPS.h"
//
////void VenusGPS::init(){
////
////		payload = 0;
////        m_restart_t restart;
////        uint16_t len = sizeof(m_restart_t);
////        //memset(&restart, 0, len);
////		restart.start_mode = 0x03;//0x03 for cold restart
////		restart.altitude = 50;
////		restart.latitude = 4227;  //these values are fairly accurate
////		restart.longitude = -7234;
////		restart.utc_year = 2012;	
////        payload = (uint8_t*) &restart;
////        //send(M_RESTART, payload, len);
////
////}
////
////
////uint8_t VenusGPS::calcCRC(uint8_t type, uint8_t pldCRC[], uint8_t start, uint16_t runlen){
//// uint8_t crc = 0, n=0;
////
//// crc ^= type;
////
//// for(n=start; n<runlen; n++){
////         crc ^=pldCRC[n];
//// }
////
//// return crc;
////}
////
////
////void VenusGPS::send(uint8_t type, uint8_t pldSending[], uint16_t len){
////        int n;
////        uint8_t crc;
////
////        crc = calcCRC(type, pldSending, 0, len);
////
////        Serial.write(START1);
////        Serial.write(START2);
////        Serial.write((uint8_t*)&len, 2);
////        Serial.write(type);
////
////        Serial.write(payload, len);
////
////        Serial.write(crc);
////        Serial.write(END1);
////        Serial.write(END2);
////}
//
//
//
//uint32_t pack4(uint8_t byteStart){
//	uint8_t* bytes = &byteStart;
//	uint32_t temp = 0;
//
//	uint32_t result = static_cast<uint32_t>(bytes[3]);
//	result = result | (static_cast<uint32_t>(bytes[2]) << 8);
//	temp = static_cast<uint32_t>(bytes[1]) << 8;
//	result = result | (temp << 8);
//	temp = 0;
//	temp = static_cast<uint32_t>(bytes[0]) << 8;
//	temp = temp << 8;
//	result = result | (temp << 8);
//
//	return result;
//}
//
//uint16_t pack2(uint8_t byteStart){
//	uint8_t* bytes = &byteStart;
//
//	uint16_t result = static_cast<uint16_t>(bytes[1]);
//	result = result | (static_cast<uint32_t>(bytes[0])<<8);
//	return result;
//}
//
//
//
//void GPS::process(uint8_t GPS_packet[]){
//	
//	//mo_navdata_t GPSin;
//
//	//GPSin.gps_week = pack2(GPS_packet[6]);
//	//GPSin.lattitude = pack4(GPS_packet[12]);
//	//GPSin.longitude = pack4(GPS_packet[16]);
//
//	numSats = GPS_packet[5];
//
//	uint32_t combinedLat=0, tempLat=0, combinedLon=0, tempLon=0;
//	uint32_t lat1 = GPS_packet[12];
//	uint32_t lat2 = GPS_packet[13];
//	uint32_t lat3 = GPS_packet[14];
//	uint32_t lat4 = GPS_packet[15];
//
//	uint32_t lon1 = GPS_packet[16];
//	uint32_t lon2 = GPS_packet[17];
//	uint32_t lon3 = GPS_packet[18];
//	uint32_t lon4 = GPS_packet[19];
//
//	combinedLat = lat4;
//	combinedLat = combinedLat | (lat3 << 8);
//	tempLat = lat2 << 8;
//	combinedLat = combinedLat | (tempLat << 8);
//	tempLat = 0;
//	tempLat = lat1 << 8;
//	tempLat = tempLat << 8;
//	combinedLat = combinedLat | (tempLat << 8);
//
//	combinedLon = lon4;
//	combinedLon = combinedLon | (lon3 << 8);
//	tempLon = lon2 << 8;
//	combinedLon = combinedLon | (tempLon << 8);
//	tempLon = 0;
//	tempLon = lon1 << 8;
//	tempLon = tempLon << 8;
//	combinedLon = combinedLon | (tempLon << 8);
//
//
//	double dbLongitude, dbLatitude;
//
//	if((combinedLat & 0x80000000) == 0x80000000)		// NEGATIVE LATITUDE
//	{
//		combinedLat = ~combinedLat;
//		combinedLat += 0x00000001;
//		dbLatitude = (double) combinedLat;
//		dbLatitude /= 10000000;
//		dbLatitude *= -1;
//	}
//	else											// POSITIVE LATITUDE
//	{
//		dbLatitude = (double) combinedLat;
//		dbLatitude /= 10000000;
//	}
//
//	if((combinedLon & 0x80000000) == 0x80000000)		// NEGATIVE LONGITUDE
//	{
//		combinedLon = ~combinedLon;
//		combinedLon += 0x00000001;
//		dbLongitude = (double) combinedLon;
//		dbLongitude /= 10000000;
//		dbLongitude *= -1;
//	}
//	else											// POSITIVE LONGITUDE
//	{
//		dbLongitude = (double) combinedLon;
//		dbLongitude /= 10000000;
//	}
//
//	
//	//do something with our new data
//	int i;
//	for(i=1; i<MAX_GPS_RECORDS; i++){
//		recentGPS[i]=recentGPS[i-1];
//	}
//
//	recentGPS[0] = Coordinate(dbLatitude, dbLongitude);
//
//	newGPS=true;
//}
//
